package edu.lingnan.house.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.lingnan.house.pojo.TbBooking;
import edu.lingnan.house.pojo.TbUser;
import edu.lingnan.house.service.TbBookingService;
import edu.lingnan.house.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/tbbooking")
public class AppointmentController {
    @Autowired(required = false)
    private TbBookingService tbBookingService;
    @Autowired
    private TbUserService tbUserService;

    @GetMapping("/getbooking")
    @ResponseBody
    public List<TbBooking> getBooking(HttpSession session){
        TbUser tbUser = tbUserService.getById(134);
        session.setAttribute("tbUser",tbUser);
        System.out.println("hhh"+tbUser);
        TbUser tbUser1 = (TbUser) session.getAttribute("tbUser");
        String id = tbUser1.getId();
        QueryWrapper<TbBooking> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        List<TbBooking> bookings = tbBookingService.list(queryWrapper);
         return bookings;
    }





}
